﻿
function main() {
    var testVersion = "(201901021555)版";
    var softwareName = "抖音";
    var view = RequestEngine.getWebView();
    var viewJson = JSON.parse(view);
    var search = viewJson.search;
    var index = viewJson._idx;
    var zanPinType = viewJson.issixin; //是否评论  0 不  1 发
    var fanYeNum = viewJson.fenSiNum; //评论个数
    var contentArr = viewJson.contentArr;
    var dengdai = viewJson.dengdai;
    AccessibilityEngine.sleepEngine(5000);// 等待
    var search1 = viewJson.search;
    var searchSp=search1.split("||");
    if ( searchSp.length < index+1 ) {
         setTaskState("6", "手机数量大于搜索内容数量");
         throw SyntaxError();
     }
    // chuSiHua(widget.pages.shouye.bugengxin);
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
    }
    var jixing = getXYByIdIndex(widget.pages.shouye.wode);
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
    }
    AccessibilityEngine.mockOnClickId(widget.pages.shouye.shousuo); // 点击搜索 放大镜
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
    }

    if( jixing == 1 ){
        ScreenEngine.swipe(parseX(300), parseY(100), parseX(300), parseY(100), 500); //点击
    } else if( jixing == 2 ){
        ScreenEngine.swipe(parseX(400), parseY(100), parseX(400), parseY(100), 500); //点击
    }
	
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
    }
    AccessibilityEngine.sleepEngine(2000);//等待
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) {//更新以后再说
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
    }
    AccessibilityEngine.mockEditId(widget.pages.shouye.shousuopinglunKuang, searchSp[index]); //赋值搜索框
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) {//更新以后再说
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
    }
    AccessibilityEngine.sleepEngine(2000);//等待
	
	
   //搜索按钮
    if (jixing == 1) {
        ScreenEngine.swipe(parseX(665), parseY(1219), parseX(665), parseY(1219), 500); //点击
    } else if (jixing == 2) {
		AccessibilityEngine.sleepEngine(5000);//等待
		//ScreenEngine.swipe(parseX(480), parseY(715), parseX(480), parseY(715), 500); //点击	
		ScreenEngine.swipe(parseX(700), parseY(1200), parseX(700), parseY(1200), 500); //点击
    }
	

	
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
    }
    AccessibilityEngine.sleepEngine(1000);//等待
    if (AccessibilityEngine.checkUpIdText("android:id/text1", "视频") == ISTRUE) {
        AccessibilityEngine.mockOnClickIdText("android:id/text1", "视频"); // 点击视频

    }
    AccessibilityEngine.sleepEngine(1000);//等待
    if (AccessibilityEngine.checkUpId("com.ss.android.ugc.aweme:id/cvz") == ISTRUE) {
        AccessibilityEngine.mockOnClickIdIndex("com.ss.android.ugc.aweme:id/cvz", 1); // 点击第一个视频
    }
    AccessibilityEngine.sleepEngine(1000);//等待
    for (var fanYeNumF = 0; fanYeNumF < fanYeNum; fanYeNumF++) {
        AccessibilityEngine.sleepEngine(dengdai*1000);//等待
        if (zanPinType == 0) {
            dianZan();
        } else if (zanPinType == 1) {
            dianZan();
            pinPun();
        }
        ScreenEngine.swipe(parseX(450), parseY(900), parseX(450), parseY(200), 500);
    }
   setTaskState("5", "执行成功");
   throw SyntaxError();


    function dianZan() {
        AccessibilityEngine.sleepEngine(1000);//等待
        var pressDianZan = "press," + parseX(250) + "," + parseY(350);
        ScreenEngine.currency(pressDianZan);
        AccessibilityEngine.sleepEngine(50);
        ScreenEngine.currency(pressDianZan);
        AccessibilityEngine.sleepEngine(50);
        ScreenEngine.currency(pressDianZan);
        AccessibilityEngine.sleepEngine(50);
        ScreenEngine.currency(pressDianZan);
        AccessibilityEngine.sleepEngine(50);
        ScreenEngine.currency(pressDianZan);
        AccessibilityEngine.sleepEngine(50);
        ScreenEngine.currency(pressDianZan);
        AccessibilityEngine.sleepEngine(1000);//等待
    }
    function pinPun() {
			AccessibilityEngine.sleepEngine(500);//等待
			 if( jixing == 1 ){
             ScreenEngine.swipe(parseX(205), parseY(1240), parseX(205), parseY(1240), 500); //
			 AccessibilityEngine.sleepEngine(1000);//等待
             var paramContent = contentArr[Math.floor(Math.random() * contentArr.length)];
             AccessibilityEngine.mockEditId(widget.pages.shouye.pinglunKuang, paramContent); //赋值
             AccessibilityEngine.mockOnClickId(widget.pages.shouye.fasong); // 发送
             AccessibilityEngine.sleepEngine(1000)
             if (AccessibilityEngine.getEditText(widget.pages.shouye.pinglunKuang) == paramContent) {
                AccessibilityEngine.mockBack();
             }
             AccessibilityEngine.sleepEngine(3000);//等待       
              } else if( jixing == 2 ){
              AccessibilityEngine.sleepEngine(2000);//等待
              ScreenEngine.swipe(parseX(667), parseY(760), parseX(667), parseY(760), 500); 	
              if (AccessibilityEngine.checkUpId(widget.pages.shouye.pinglunKuang) == ISTRUE) {
              AccessibilityEngine.mockOnClickId(widget.pages.shouye.pinglunKuang); // 点击评论
              AccessibilityEngine.sleepEngine(1000);//等待
              var paramContent = contentArr[Math.floor(Math.random() * contentArr.length)];
              AccessibilityEngine.mockEditId(widget.pages.shouye.pinglunKuang, paramContent); //赋值
              AccessibilityEngine.mockOnClickId(widget.pages.shouye.fasong); // 发送
              AccessibilityEngine.sleepEngine(1000)
			  if ( AccessibilityEngine.checkUpId(widget.pages.shouye.pinglunKuang) == ISTRUE){
               showLog("点击返回");
               AccessibilityEngine.mockBack();
              }
               AccessibilityEngine.sleepEngine(3000);//等待
              }
            }						

    }
}

var publicfunction = RequestEngine.getPluginPath() + "OS_DYCOMMON/publicfunction.js";
include(publicfunction); //公共方法js
var widgetPath = dyConditionCheck();
var widgetbyid = RequestEngine.getPluginPath() +"OS_DYCOMMON/"+ widgetPath;
include(widgetbyid);
main();